// page/pack-service/pages/government-public/street-details/street-details.js
var toolUtils = require("../../../../../utils/tool-utils.js")
var httpUtils = require('../../../../../utils/https-service-utils.js')
var that
var id
var windowWidth
Page({

  /**
   * 页面的初始数据
   */
  data: {
    is_spread: false,
    isShow: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that = this
    //获取屏幕宽度
    try {
      var res = wx.getSystemInfoSync()
      windowWidth = res.windowWidth
    } catch (e) {
      toolutils.showFailToast("获取屏幕宽度失败")
      // Do something when catch error
    }
    id = options.id
    wx.setNavigationBarTitle({
      title: options.title
    });
    getData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  //获取控件在屏幕的位置
  getFields: function () {
    wx.createSelectorQuery().select('#community_detail').fields({
      size: true,
      rect: true
    }, function (res) {
      console.log(res)
      var height = res.height
      var height_rpx = windowWidth * height / 750
      console.log(height_rpx)
      if (height_rpx > 280) {
        that.setData({
          is_spread: true
        })
      }else{
        that.setData({
          is_spread: false
        })
      }
    }).exec()
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //展开更多
  getMore: function () {
    that.setData({
      isShow: !that.data.isShow
    })
  }
})

function getData() {
  httpUtils.getZwgkStreetDetails(id, {}, function (res) {
    that.setData({
      streetData: res
    })
    setTimeout(function () {
      that.getFields()
    }, 150)

  }, function (e) {

  })
}